package cn.tj.student.web.servlet;

import cn.tj.student.dao.UserDao;
import cn.tj.student.dao.impl.UserDaoImpl;
import cn.tj.student.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/regist")
public class RegistServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        UserDao userDao=new UserDaoImpl();
        int row = userDao.insertUser(new User(null,username,password));
        if(row>0){
            //resp.getWriter().write("注册成功");
            //req.getRequestDispatcher("/login.jsp").forward(req,resp);
            resp.sendRedirect("/login.jsp");
        }
    }
}
